package com.dahai.gameinfo;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalDefaultExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody   // 如果返回String或json要加此注解如果返回界面就不加
    public ResultData defaultExceptionHandler(HttpServletRequest req, Exception e) {
        ResultData result = new ResultData();
        System.out.println("有异常啦");
        result.setState(-1);
        result.setMessage(e.getMessage());
        return result;
    }
}
